home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2005 November
/
WNnov2005.iso
/
Windows
/
Indispensables
/
Movie Collection
/
MovieCollection5403.exe
/
{app}
/
php5
/
updatebdd.class.php
< prev
Wrap
PHP Script
|
2005-05-16
|
8KB
|
256 lines
<?php
header("Pragma: no-cache");
//set_time_limit(0);
include_once('sql.class.php');
class TmcSqlXmlInitialize
{
private $doc = null;
private $xpath = null;
private $sql=null;
private $cpt=0;
private $array_fields = array();
private $array_fields_name = array();
private $array_fields_table = array();
private $array_fields_values = array();
function __construct($AxmlFileName, $AShowTrace)
{
$this->doc = new DOMDocument();
$this->doc->load($AxmlFileName);
$this->xpath = new DOMXPath($this->doc);
$this->sql = new TmcSql($AShowTrace, TRUE);
$echo=<<<MSG
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Mise α jour de la base de donnΘe Movie collection</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.text {
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
font-weight: normal;
color: #000000;
}
a:link {
color: #003366;
text-decoration: none;
}
a:hover {
text-decoration: underline;
color: #003366;
}
a:visited {
color: #003366;
text-decoration: none;
}
a:visited:hover {
color: #003366;
text-decoration: underline;
}
.titre {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
font-style: normal;
font-weight: bold;
text-decoration: underline;
color: #000000;
}
-->
</style>
</head>
<body>
<table width="70%" cellspacing="0" bgcolor="#EDEDED" class='text'>
<tr>
<td bordercolor="#EDEDED" bgcolor="#EDEDED">
MSG;
print($echo);
}
function deleteEmpty()
{
unlink('empty.inc');
}
function __destruct()
{
$this->writeHtmlMsg('<b>Mise α jour terminΘe</b>');
$ext = $_SESSION["mc_params"]->getPhpExtension();
$echo=<<<MSG
<form name="formAccueil" method="post" action="index$ext" >
<input type="submit" name="submitGo" value="AccΘder au site" />
</form>
</td>
</tr>
</table>
</body>
</html>
MSG;
print($echo);
}
function writeHtmlMsg($Amsg)
{
$this->cpt++;
$echo=<<<MSG
<div id="idwrite{$this->cpt}">$Amsg<div>
<!--$Amsg<br />-->
MSG;
print("\n".$echo);
flush();
ob_flush();
}
function loadFieldDefs()
{
$this->writeHtmlMsg('<b>Lecture de la structure de la base de donnΘe</b>');
$res = $this->xpath->query('//DATAPACKET/METADATA/FIELDS/FIELD');
$i=0;
foreach ($res as $node)
{
$i++;
$fieldtype=$node->getAttribute('fieldtype');
$fieldsubtype=$node->getAttribute('SUBTYPE');
if (strlen($fieldtype)>0)
{
if (($fieldtype=='string') or ($fieldtype=='date') or (($fieldtype=='bin.hex') and ($fieldsubtype=='Text')))
{
$this->array_fields[$i] = array($node->getAttribute('attrname'), 'string');
$this->array_fields_name[$i] = $node->getAttribute('attrname');
$this->array_fields_table[$i] = $node->getAttribute('attrname').' string';
}
elseif ($fieldtype[0]=='i')
{
$this->array_fields[$i] = array($node->getAttribute('attrname'), 'int');
$this->array_fields_name[$i] = $node->getAttribute('attrname');
$this->array_fields_table[$i] = $node->getAttribute('attrname').' int';
}
elseif ($fieldtype[0]=='r')
{
$this->array_fields[$i] = array($node->getAttribute('attrname'), 'real');
$this->array_fields_name[$i] = $node->getAttribute('attrname');
$this->array_fields_table[$i] = $node->getAttribute('attrname').' real';
}
}
}
}
function createTableFilms()
{
$stmt = '';
$stmt .='create table t_film ('."\n";
$stmt .= implode(', ', $this->array_fields_table);
$stmt .= ')';
$this->writeHtmlMsg("<b>Suppression de la table 't_film' </b>");
$this->sql->execSql_no_exception('drop table t_film');
$this->writeHtmlMsg("<b>CrΘation de la table 't_film' </b>");
$this->sql->execSql($stmt);
}
function createCollection()
{
$stmt = '';
$stmt .='create table t_collection ('."\n";
$stmt .='IDX int, COLLECTION string'."\n";
$stmt .= ')';
$this->writeHtmlMsg("<b>Suppression de la table 't_collection' </b>");
$this->sql->execSql_no_exception('drop table t_collection');
$this->writeHtmlMsg("<b>CrΘation de la table 't_collection' </b>");
$this->sql->execSql($stmt);
}
function createCategorie()
{
$stmt = '';
$stmt .='create table t_categorie ('."\n";
$stmt .='IDX int, CATEGORIE string'."\n";
$stmt .= ')';
$this->writeHtmlMsg("<b>Suppression de la table 't_categorie' </b>");
$this->sql->execSql_no_exception('drop table t_categorie');
$this->writeHtmlMsg("<b>CrΘation de la table 't_categorie' </b>");
$this->sql->execSql($stmt);
}
function fillFilms()
{
$this->writeHtmlMsg("<b>Remplissage de la table 't_film' </b>");
$res = $this->xpath->query('//DATAPACKET/ROWDATA/ROW');
$stmt = '';
$count_enreg = 0;
foreach ($res as $node)
{
foreach ($this->array_fields_name as $key => $field)
{
$fieldvalue=utf8_decode($node->getAttribute($field));
if ($this->array_fields[$key][1]=='string')
$this->array_fields_values[$key] = "'".sqlite_escape_string($fieldvalue)."'";
else
$this->array_fields_values[$key] = $fieldvalue;
if ($fieldvalue=='')
$this->array_fields_values[$key] = 'null';
}
$stmt = 'insert into t_film ('.implode(', ', $this->array_fields_name).') values ('.
implode(', ', $this->array_fields_values).')';
$this->sql->execSql($stmt);
$count_enreg++;
}
$this->writeHtmlMsg(" $count_enreg enregistrements insΘrΘs");
}
function fillCollections()
{
$this->writeHtmlMsg("<b>Remplissage de la table 't_collection' </b>");
$stmt = 'select distinct idcollection, collection from t_film where idcollection is not null order by collection';
$result=$this->sql->openSql($stmt);
$count_enreg = 0;
foreach ($result as $idrow => $row)
{
$idcollection = $row['idcollection'];
$collection = sqlite_escape_string($row['collection']);
$stmt = "insert into t_collection (idx, collection) values ($idcollection, '$collection')";
$this->sql->execSql($stmt);
$count_enreg++;
}
$this->writeHtmlMsg(" $count_enreg enregistrements insΘrΘs");
}
function fillCategories()
{
$this->writeHtmlMsg("<b>Remplissage de la table 't_categorie' </b>");
$stmt = 'select distinct idcategorie, categorie from t_film where idcategorie is not null order by categorie';
$result=$this->sql->openSql($stmt);
$count_enreg = 0;
foreach ($result as $idrow => $row)
{
$idcategorie = $row['idcategorie'];
$categorie = sqlite_escape_string($row['categorie']);
$stmt = "insert into t_categorie (idx, categorie) values ($idcategorie, '$categorie')";
$this->sql->execSql($stmt);
$count_enreg++;
}
$this->writeHtmlMsg(" $count_enreg enregistrements insΘrΘs");
}
}
?>